import sys
sys.path.append("..")
from database.db_handler import MysqlHander
from common.my_http import MyHttp
import urllib.request
from bs4 import BeautifulSoup
from common.entity_data import EntityData
import glob
import jieba
import re
import threading
import hashlib

'''
港口
'''

class GangguData:
    def __init__(self):
        self.entity = EntityData()
        pass
    
    def get_data(self):
        url = "http://app.finance.ifeng.com/hq/list.php?type=hkstock&class=gp"
        bs4_data = MyHttp.bs4_utf8_data(url)
        data_set = ""
        for a in bs4_data.find(name="div", attrs={'class':'result'}).find("ul").find_all("a"):
            href = "https://gangkou.bmcx.com" + a["href"]
            data_set += "|" + a.text.replace(" ", "").split("(")[0].split("（")[0].split("─")[0]

        print(data_set)
        self.entity.add_entity_data("港股列表", "", 100, 1000001, "港股", "", data_set)
        self.entity.update_entity_data("港股列表", "", 100, 1000001, "港股", "", data_set)

        

def ganggu_api():
    d = GangguData()
    d.get_data()

if __name__ == '__main__':
    ganggu_api()
